package com.yhx.controller;

import com.yhx.iservice.IMemberService;
import com.yhx.pojo.Member;
import com.yhx.utils.MessageConstant;
import com.yhx.utils.PageResult;
import com.yhx.utils.QueryPageBean;
import com.yhx.utils.Result;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/member")
public class MemberController {
    @Reference(timeout = 60000)
    private IMemberService iMemberService;

//    @PostMapping("listpage")
//    public PageResult listpage(@RequestBody QueryPageBean queryPageBean){
//        try {
//            PageResult pagelist = iMemberService.pagelist(queryPageBean);
//            return pagelist;
//        } catch (Exception e) {
//            e.printStackTrace();
//            return null;
//        }
//    }
    @GetMapping("/regTimelist2")
    public Result regTime(){
        try {
            Result creTimeList = iMemberService.getCreTimeList();
            return creTimeList;
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.DELETE_CHECKGROUP_FAIL);
        }
    }
    @PostMapping("listpage2")
    public PageResult listpage2(@RequestBody QueryPageBean queryPageBean){
        try {
            PageResult pagelist = iMemberService.pagelist2(queryPageBean);
            return pagelist;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @PostMapping
    public Result save(@RequestBody Member member){
        try {
            Result save = iMemberService.save(member);
            return save;
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.ADD_MEMBER_FAIL);
        }
    }
    
    @GetMapping("/{id}")
    public Result getByid(@PathVariable int id){
        try {
            Result result = iMemberService.getByid(id);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.EDIT_MEMBER_FAIL);
        }
    }
    @PutMapping
    public Result update(@RequestBody Member member){
        try {
            Result update = iMemberService.update(member);
            return update;
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.EDIT_MEMBER_FAIL);
        }
    }
    
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable int id){
        try {
            Result delete = iMemberService.delete(id);
            return delete;
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.DELETE_MEMBER_FAIL);
        }
    }
    
    @DeleteMapping
    public Result deleteAll(Integer[] ids){
        try {
            Result result = iMemberService.deleteAll(ids);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.DELETE_MEMBER_FAIL);
        }
    }
    @GetMapping("/sex")
    public Result sexbili(){
        try {
            List<Map<String, Object>> sexbili = iMemberService.sexbili();
            return new Result(true, MessageConstant.GET_BUSINESS_REPORT_FAIL,sexbili);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_BUSINESS_REPORT_FAIL);
        }
    }

    @GetMapping("between")
    public Result between(){
        try {
            List<Long> between = iMemberService.between();
            List<Long> sum=iMemberService.sum();
            return new Result(true, MessageConstant.GET_BUSINESS_REPORT_SUCCESS,between,sum);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_BUSINESS_REPORT_FAIL);
        }

    }


}
